package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppRealName;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 实名认证
 */
@Repository
public class AppRealNameDao extends BaseDao<AppRealName> {

    /**
     * 查询列表
     */
    public List<AppRealName> list(Map<String,Object> paraMap, SplitPageBean splitPage) {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_real_name where 1=1  ");
        sbStr.append(" order by createtime desc");
        String sql = sbStr.toString();
        return this.queryList(sql,paramList, AppRealName.class,splitPage);
    }


    /**
     * 详情
     */
    public AppRealName get(Integer id) {
        if (StringEx.isNullOrLing(id)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_real_name where 1=1");
        sbStr.append(" and id = ? ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppRealName.class);
    }

    /**
     * 添加/修改
     */
    public void save(AppRealName haoYou) {
        if (haoYou.getId() != null && haoYou.getId() > 0) {
            this.update(haoYou);
        } else {
            haoYou.setId(this.add(haoYou));
        }
    }

    /**
     * 删除
     */
    public void del(Integer id) {
        if (id <= 0) {
            return;
        }
        String sql = "delete  from app_real_name where id = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }
    /**
     * 后天管理获取所有用户
     * @param map
     * @param bean
     * @return
     */
    public List<AppRealName> findList(Map<String, Object> map, SplitPageBean bean) {
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("");
        sbStr.append(" SELECT a.* FROM app_real_name a where 1=1 ");
        if (StringEx.isNotNull(map.get("nick"))) {
            sbStr.append(" and a.nick like ? ");
            paramList.add("%" + map.get("nick") + "%");
        }
        if (StringEx.isNotNull(map.get("status"))) {
            sbStr.append(" and a.status = ? ");
            paramList.add(map.get("status"));
        }
        if(StringEx.isNotNull(map.get("phone"))){
            sbStr.append(" and a.phone = ? ");
            paramList.add(map.get("phone"));
        }
        if (!StringEx.isNull(map.get("startDate"))) {
            sbStr.append(" and a.createtime>=? ");
            paramList.add(map.get("startDate"));
        }
        if (!StringEx.isNull(map.get("endDate"))) {
            sbStr.append(" and a.createtime<=? ");
            paramList.add(map.get("endDate"));
        }
        sbStr.append(" order by a.createtime desc ");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppRealName.class, bean);
    }

    /**
    * 获取用户实名认证信息
    * @Param: [userid 用户id]
    * @return: com.vf.admin.miaodong.entity.AppRealName
    * @Author: zhouyunyi
    * @Date: 2021/10/22
    * @Time: 12:28
    */
    public AppRealName getReal(Integer userid){
        if (StringEx.isNullOrLing(userid)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder(" select * from app_real_name where 1=1 ");
        sbStr.append(" and userid = ? ");
        paramList.add(userid);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppRealName.class);

    }
    /**
     * 更新用户头像
     * @param userid
     * @param pic 头像地址
     */
    public void updateImg(Integer userid,String pic){
        if(StringEx.isNull(userid)){
            return ;
        }
        if(StringEx.isNull(pic)){
            return;
        }
        String sql = " UPDATE app_real_name SET pic = ?  WHERE userid = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(pic);
        paramList.add(userid);
        this.update(sql,paramList);
    }
    /**
     * 更新用户昵称
     * @param userid
     * @param nick 昵称
     */
    public void updateNick(Integer userid,String nick){
        if(StringEx.isNull(userid)){
            return ;
        }
        if(StringEx.isNull(nick)){
            return;
        }
        String sql = " UPDATE app_real_name SET nick = ?  WHERE userid = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(nick);
        paramList.add(userid);
        this.update(sql,paramList);
    }

    public List<AppRealName> selectList() {
        StringBuilder str = new StringBuilder();
        str.append("select * from app_real_name limit 0,6");
        List list =new ArrayList();
        String sql = str.toString();
        return this.queryList(sql,list,AppRealName.class);
    }

    public List<AppRealName> userCount() {
        StringBuilder str = new StringBuilder();
        str.append("select * from app_real_name where status=1");
        List list =new ArrayList();
        String sql = str.toString();
        return this.queryList(sql,list,AppRealName.class);
    }
}
